﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 版权所有 (c) 2022 北京超维景生物科技有限公司 保留所有权利。
 * 
 * 创建者：huangyang
 * 电子邮箱：huangyang@tvscope.cn
 * 创建时间：2023/3/13 19:27:37
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageK.Gui
{
	/** This is an extension of GenericDialog that is non-modal.
     *	@author Johannes Schindelin
     */
	public class NonBlockingGenericDialog : GenericDialog
	{
		public ImagePlus imp;                  //when non-null, this dialog gets closed when the image is closed
		// WindowListener windowListener;  //checking for whether the associated window gets closed

	    public NonBlockingGenericDialog(String title): base(title, null)
        {
		    // setModal(false);
		    IJ.protectStatusBar(false);
		    instance = this;
	    }

	    public void showDialog()
	    {
		    base.showDialog();
		    // if (isMacro())
			   //  return;
		    if (!IJ.MacroRunning())
		    {   // add to Window menu on event dispatch thread
			    // final NonBlockingGenericDialog thisDialog = this;
			    // EventQueue.invokeLater(new Runnable()
			    // {
				   //  public void run()
			    // {
				   //  WindowManager.addWindow(thisDialog);
			    // }
		        // });
	        }
		    if (imp != null) {
			    ImageWindow win = imp.getWindow();
			    if (win != null) {      //when the associated image closes, also close the dialog
				    // NonBlockingGenericDialog gd = this;
	       //          windowListener = new WindowAdapter()
	       //          {
		      //           public void windowClosed(WindowEvent e)
		      //           {
			     //            cancelDialogAndClose();
		      //           }
	       //          };
	       //          win.addWindowListener(windowListener);
			    }
		    }
		    // try
      //       {
	     //        wait();
      //       }
      //       catch (InterruptedException e) { }
	    }

	    /** Gets called if the associated image window is closed */
	    // private void cancelDialogAndClose()
     //    {
	    //     base.windowClosing(null);  // sets wasCanceled=true and does dispose()
     //    }
     //
     //    public synchronized void actionPerformed(ActionEvent e)
     //    {
	    //     super.actionPerformed(e);
	    //     if (!isVisible())
		   //      notify();
     //    }
     //
     //    public synchronized void keyPressed(KeyEvent e)
     //    {
	    //     super.keyPressed(e);
	    //     if (wasOKed() || wasCanceled())
		   //      notify();
     //    }
     //
     //    public synchronized void windowClosing(WindowEvent e)
     //    {
	    //     super.windowClosing(e);
	    //     if (wasOKed() || wasCanceled())
		   //      notify();
     //    }
     //
     //    public void dispose()
     //    {
	    //     super.dispose();
	    //     WindowManager.removeWindow(this);
	    //     if (imp != null)
	    //     {
		   //      ImageWindow win = imp.getWindow();
		   //      if (win != null && windowListener != null)
			  //       win.removeWindowListener(windowListener);
	    //     }
     //    }
     //
     //    /** Obsolete, replaced by GUI.newNonBlockingDialog(String,ImagePlus). */
     //    public static GenericDialog newDialog(String title, ImagePlus imp)
     //    {
	    //     return GUI.newNonBlockingDialog(title, imp);
     //    }
     //
     //    /** Obsolete, replaced by GUI.newNonBlockingDialog(String). */
     //    public static GenericDialog newDialog(String title)
     //    {
	    //     return GUI.newNonBlockingDialog(title);
     //    }
     //
     //    /** Put the dialog into the foreground when the image we work on gets into the foreground */
     //    public void windowActivated(WindowEvent e)
     //    {
	    //     if ((e.getWindow() is ImageWindow) && e.getOppositeWindow() != this)
			  //       toFront();
     //        WindowManager.setWindow(this);
	    // }

    }
}
